<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    //获取&&修改表达元素属性
    <input type="checkbox" class="all" onclick="SelectAll()">勾选全部 <br>
    <input type="checkbox" class="select">选项1 <br>
    <input type="checkbox" class="select">选项2 <br>
    <input type="checkbox" class="select">选项3 <br>
    <input type="checkbox" class="select">选项4 <br>
</body>
<script>
    //获取事件源
    let all = document.querySelector(".all");
    let select = document.querySelectorAll(".select");
    function SelectAll() {
        for (i = 0; i < select.length; i++) {
            select[i].checked = all.checked;
        }
    }

    //为子选框进行操作
    for (let i = 0; i < select.length; i++) {
        select[i].onclick = function () {
            all.checked = isSelectAll(select);
        }
    }

    function isSelectAll() {
        for (i = 0; i < select.length; i++) {
            if (select[i].checked == false)
                return false;
        }
        return true;
    }
</script>

</html>